package com.dianping.cat.home.group;

import com.dianping.cat.home.group.transform.DefaultJsonBuilder;
import com.dianping.cat.home.group.transform.DefaultXmlBuilder;
import java.util.Formattable;
import java.util.Formatter;




public abstract class BaseEntity<T>
  extends Object
  implements IEntity<T>, Formattable
{
  public static final String JSON = "%#.3s";
  public static final String JSON_COMPACT = "%#s";
  public static final String XML = "%.3s";
  public static final String XML_COMPACT = "%s";
  
  protected void assertAttributeEquals(Object instance, String entityName, String name, Object expectedValue, Object actualValue) {
/* 21 */     if ((expectedValue == null && actualValue != null) || (expectedValue != null && !expectedValue.equals(actualValue))) {
/* 22 */       throw new IllegalArgumentException(String.format("Mismatched entity(%s) found! Same %s attribute is expected! %s: %s.", new Object[] { entityName, name, entityName, instance }));
    }
  }
  
  protected boolean equals(Object o1, Object o2) {
/* 27 */     if (o1 == null)
/* 28 */       return (o2 == null); 
/* 29 */     if (o2 == null) {
/* 30 */       return false;
    }
/* 32 */     return o1.equals(o2);
  }


  
  public void formatTo(Formatter formatter, int flags, int width, int precision) {
/* 38 */     boolean useJson = ((flags & 0x4) == 4);
/* 39 */     boolean compact = (precision <= 0);

/* 41 */     if (useJson) {
/* 42 */       DefaultJsonBuilder builder = new DefaultJsonBuilder(compact);

/* 44 */       formatter.format("%s", new Object[] { builder.build(this) });
    } else {
/* 46 */       DefaultXmlBuilder builder = new DefaultXmlBuilder(compact);

/* 48 */       formatter.format("%s", new Object[] { builder.buildXml(this) });
    }
  }


  
/* 54 */   public String toString() { return (new DefaultXmlBuilder()).buildXml(this); }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/group/BaseEntity.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */